<#include "/common/head.html"/>
<table id="dg"></table>
<div id="tb" style="padding: 2px 5px;">
	<div class="wrap_search">
		<span class="search_item" style="width: 100%"> <span class="item_text">合同分类: </span> <span class="item_obj"
			style="width: 220px;"> <input class="easyui-combobox" name="classify_value" id="classify_value" value=""
				style="width: 200px"
				data-options="valueField: 'id',
					textField: 'text',
					data: [{id:'', text:''}<#list classify.keySet() as key>,{id:'${key}', 
					text:'${classify.get(key)}'}</#list>]" />
		</span>
		</span>
	</div>

	<div style="text-align: left; margin: 6px;">
		<a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add()">增加</a>
		<a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true"
			onclick="update()">编辑</a> <a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove"
			plain="true" onclick="del()">删除</a>
		<div id="searchBtnWrap" style="float: right; padding-right: 40px;">
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="glyphicon-search" onclick="zcurdSearch(this)">搜索</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="glyphicon-repeat" onclick="flushPage()">重置</a>
		</div>
	</div>
</div>

<script type="text/javascript">
	var datagrid = $("#dg");

	var dgOptions = {
		rownumbers : true,
		fit : true,
		border : false,
		rownumbers : true,
		url : 'listData',
		method : 'post',
		toolbar : '#tb',
		pageSize : 20,
		pagination : true,
		multiSort : true,
		singleSelect : false,
		queryParams : getInitParam(),
		columns : [ [ {
			field : 'id',
			checkbox : true
		}, {
			field : 'template_name',
			title : '模板名称',
			sortable : true
		}, {
			field : 'classify_value',
			title : '所属分类',
			sortable : true
		}, {
			field : 'operate',
			title : '操作',
			width : 140,
			frozen : true,
			formatter : function(value, row, index) {
				var html = "";
				html += '<a class="operate" href="###" onclick="upload(' + row.id + ')">上传模板</a>';
				html += '<a class="operate" href="###" onclick="downloadFile(' + row.id + ')">下载模板</a>';
				return html;
			}
		} ] ],
		loadFilter : function(data) {
			if (data.result && data.result == 'fail') { //失败时，错误消息提示
				showWarnMsg(data.msg);
				return {};
			} else {
				return data;
			}
		}
	};
	$(function() {
		handleAuthDataRule();
		datagrid.datagrid(dgOptions);
	});

	function zcurdSearch() {
		var param = zcurdGetParam();
		datagrid.datagrid("load", {
			queryParams : param
		})
	}

	function getInitParam() {
		var param = {};
		$("#tb :input[name]").each(function(i, item) {
			if ($(item).val()) {
				param["queryParams[" + $(item).attr("name") + "]"] = $(item).val();
			}
		});
		return param;
	}

	var initPara = zcurdGetParam();
	function add() {
		top.window.subPage.loadCurrDatagrid = function() {
			showMsg("增加成功！");
			datagrid.datagrid("load");
		}
		top.openWindow("合同模板-增加", getCurrUrl("addPage") + "?" + $.param(initPara), {
			size : '600x400'
		});
	}

	function zcurdGetParam() {
		var param = {};
		$("#tb :input[name]").each(function(i, item) {
			if ($(item).val()) {
				param[$(item).attr("name")] = $(item).val();
			}
		});
		return param;
	}

	function update() {
		var rowsSel = datagrid.datagrid("getSelections");
		if (rowsSel.length != 1) {
			showWarnMsg("请选择需要编辑的一条数据！");
			return;
		}
		var id = rowsSel[0].id;
		top.window.subPage.loadCurrDatagrid = function() {
			showMsg("更新成功！");
			datagrid.datagrid("reload");
		}
		top.openWindow("合同模板-编辑", getCurrUrl("updatePage") + "?id=" + id, {
			size : '600x400'
		});
	}

	function del() {
		var ids = [];
		$.each(datagrid.datagrid("getSelections"), function(i, item) {
			ids.push(item.id);
		});
		if (ids.length < 1) {
			showWarnMsg("请选择需要删除的数据！");
			return;
		}
		confirmMsg("确认删除？", function() {
			$.post("delete", {
				id : ids
			}, function(data) {
				showMsg("删除成功！");
				datagrid.datagrid("reload");
			});
		});
	}

	function upload(id) {
		top.window.subPage.loadCurrDatagrid = function() {
			showMsg("上传成功！");
			datagrid.datagrid("reload");
		}
		top.openWindow("模板上传", getCurrUrl("uploadPage") + "?id=" + id, {
			size : '600x400'
		});
	}

	function downloadFile(id) {
		top.openWindow("模板下载", getCurrUrl("downloadPage") + "?id=" + id, {
			size : '600x400'
		});
	}
</script>

<#include "/common/dialogWindow.html"/>
<#include "/common/foot.html"/>
